<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/4/12
  Time: 11:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>Title</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript">

        $(function () {
            $("#name").blur(function(){

                var name=$("#name").val();
                $.post("PersonServlet?opr=check",{name:name},function (result) {
                    if (result){
                        alert("该名字已存在!");
                    } else{
                        alert("该名字可以使用!");
                    }
                },"JSON");
            });
        });
    </script>
</head>
<body>
<form action="PersonServlet?opr=add" method="post">
    <table width="450" border="0" cellpadding="0" cellspacing="0" align="center">
        <tr>
            <td colspan="2" align="center">
                <h2>添加人员</h2>
            </td>
        </tr>
        <tr>
            <td>姓名：</td>
            <td>
                <input type="hidden" name="id" value="${ps.id}"/>
                <input type="text" name="name" value="${ps.name}" id="name"/>
            </td>
        </tr>
        <tr>
            <td>性别:</td>
            <td>
                <c:choose>
                    <c:when test="${ps==null}">
                        <input type="radio" value="1" name="gender" checked />男
                        <input type="radio" value="2" name="gender" />女
                    </c:when>
                    <c:otherwise>
                        <input type="radio" value="1" name="gender" ${ps.gender=='男'?'checked':''} />男
                        <input type="radio" value="2" name="gender" ${ps.gender=='女'?'checked':''} />女
                    </c:otherwise>
                </c:choose>

            </td>
        </tr>
        <tr>
            <td>年龄:</td>
            <td>
                <input type="text" name="age" value="${ps.age}"/>
            </td>
        </tr>

        <tr>
            <td>等级:</td>
            <td>
                <select name="rank">
                    <option value=""  ${ps==null?'selected':''}>--请选择--</option>
                    <option value="1" ${ps.rank=='等级1'?'selected':''}>等级1</option>
                    <option value="2" ${ps.rank=='等级2'?'selected':''}>等级2</option>
                    <option value="3" ${ps.rank=='等级3'?'selected':''}>等级3</option>
                    <option value="4" ${ps.rank=='等级4'?'selected':''}>等级4</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>部门:</td>
            <td>
                <input type="text" name="department" value="${ps.department}"/>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <input type="submit" value="提交"/>
                <input type="reset" value="重置"/>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
